package think.in.spring.bean.builder;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import think.in.spring.ioc.overview.domain.User;

public class BeanDefinitionBuildDemo {

    public static void main(String[] args) {
        // BeanDefinition构建
        BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(User.class);
        // 添加属性
        beanBuilder.addPropertyValue("id",11)
                .addPropertyValue("name","比利");
        // 获取BeanDefinition对象，不是最终状态，可以修改属性
        BeanDefinition beanDefinition = beanBuilder.getBeanDefinition();

        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(User.class);
        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("id",11)
                .add("name","比利");
        genericBeanDefinition.setPropertyValues(mutablePropertyValues);
    }
}
